package com.copsoftware.mantenimientos.testigo.assemblers;

import org.springframework.beans.BeanUtils;

import com.copsoftware.mantenimientos.testigo.beans.Testigo;
import com.copsoftware.mantenimientos.testigo.beans.TestigoInvestigacion;
import com.copsoftware.struts.forms.RegistrarTestigoInvestigacionForm;
import com.copsoftware.utils.beans.DateFormatter;

public class TestigoAssembler {

	public static Testigo createTestigo(RegistrarTestigoInvestigacionForm form) {
		
		Testigo testigoFlt= new Testigo();
		BeanUtils.copyProperties(form, testigoFlt,new String []{"CInvestigacion", "CPersona"});
		
				
		if (!form.getCPersona().equals(""))
		{
			testigoFlt.setCPersona(Integer.parseInt(form.getCPersona()));
		}
		
		return testigoFlt;
	}
	
	public static TestigoInvestigacion createTestigoInvestigacion(RegistrarTestigoInvestigacionForm form){
		
		TestigoInvestigacion testigoInvestigacion = new TestigoInvestigacion();
		
		if (!form.getCInvestigacion().equals(""))
			testigoInvestigacion.setCInvestigacion(Integer.parseInt(form.getCInvestigacion()));
		
		if (!form.getCPersona().equals(""))
			testigoInvestigacion.setCPersona(Integer.parseInt(form.getCPersona()));
		
		testigoInvestigacion.setXTestimonio(form.getXTestimonio());
		
		if (form.getFProgramadaTestimonio()!= null)
			testigoInvestigacion.setFProgramadaTestimonio(DateFormatter.parse(form.getFProgramadaTestimonio()));
		
		return testigoInvestigacion;
		
	}
	
	
}
